﻿using System;
using System.Text;
using System.Web;
using System.Windows.Forms;

namespace LikeProxy.Controls
{
    public partial class UrlEncodeControl : UserControl
    {
        public UrlEncodeControl()
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
        }

        private void UrlEncodeControl_Load(object sender, EventArgs e)
        {
            cb_encode_type.SelectedIndex = 0;
        }

        private void EncodeOrDecodeWithUrlButtonClicked(object sender, EventArgs e)
        {
            try
            {
                var encodingType = Encoding.GetEncoding(cb_encode_type.SelectedItem.ToString());
                Button btn = sender as Button;
                if (btn.Name == "button_url_encode")
                {
                    textBox_entext.Text = HttpUtility.UrlEncode(textBox_detext.Text.Trim(), encodingType);
                }
                else if (btn.Name == "button_url_decode")
                {
                    textBox_detext.Text = HttpUtility.UrlDecode(textBox_entext.Text.Trim(), encodingType);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("编码类型错误！", "提示");
            }

        }
    }
}
